package com.threeti.mecool.core.infrastructure.persistence;

import com.threeti.mecool.core.domain.model.Communication;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

public interface CommunicationRepository extends JpaRepository<Communication, Long>, JpaSpecificationExecutor<Communication> {
    Page<Communication> findByUser_LoginName(String userLoginName, Pageable pageable);

    /**
     * 删除特定项目的所有沟通记录<p>
     */
    @Modifying
    @Transactional
    @Query("delete from Communication c where c.project.id = ?1")
    void deleteByProjectId(Long projectId);
}
